package br.edu.unifei.cct810.trabalho01.utils;

import javax.swing.text.JTextComponent;

public class ValidaNumero {
	
	public static boolean isEmpty(String num) {
		return num.trim().equals("");
	}
	
	public static boolean validaNumero(String str_numero) {
		String valor = str_numero.replaceAll(" ", "").trim();
		return formataNumero(valor.toCharArray());		
	}
	
	public static boolean formataNumero(char[] array) {
		for(char ch : array){
			switch(ch){
				case '1':
					break;
			  
				case '2':
					break;
			  
				case '3':
					break;
			  
				case '4':
					break;
			  
				case '5':
					break;
				
				case '6':
					break;
				
				case '7':
					break;
			
				case '8':
					break;
				
				case '9':
					break;
			
				case '0':
					break;
				
				default:
					return false;
			}
		}		
		return true;
	}
	
	public static boolean validaCampo(JTextComponent txt_numero) {
		if(!(isEmpty(txt_numero.getText())) && (validaNumero(txt_numero.getText().trim()))) {
			txt_numero.setBackground(Constantes.COR_OK);			
		}
		else {
			txt_numero.setBackground(Constantes.COR_ERRO);
			return false;
		}
		
		return true;
	}	
}
